<?php

namespace IDock\Insurance\ZYIC\Response;

use IDock\Http\Response;
use IDock\IDock\IDockEnums;
use IDock\Insurance\ZYIC\ZYICEnums;
use IDock\Insurance\ZYIC\Response\AllZYICResponse;
use IDock\Printer\VehicleModelPrinter;
use IDock\Printer\VehiclePrinter;

class VehicleModelResponse extends AllZYICResponse
{

    /**
     * @var VehicleModelPrinter $printer
     */
    public $printer = VehicleModelPrinter::class;

    public function printerInit(): Response
    {
        $body = $this->getBody();
        $modelList = $body['content']['content'] ?? [];
        if (!$modelList) {
            return $this;
        }

        foreach ($modelList as $datum) {

            $vehiclePrinter = new VehiclePrinter();
            $vehiclePrinter->vehicleName = $datum['vehicleName'] ?? '';
            $vehiclePrinter->vehicleModelCode = $datum['vehicleId'] ?? '';
            $vehiclePrinter->vehicleYear = $datum['yearPattern'] ?? '';
            $vehiclePrinter->brandName = $datum['carBrandName'] ?? '';
            $vehiclePrinter->vehicleExhaust = $datum['vehicleExhaust'] ?? '';

            $vehiclePrinter->vehicleTypeCode = $datum['platModelCode'] ?? '';

            //进口车标识
            $vehicleType = $datum['vehicleType'] ?? '';
            $vehiclePrinter->vehicleImport = array_search($vehicleType,IDockEnums::$importFlag);
            $vehiclePrinter->vehicleImportName = IDockEnums::$importFlag[$vehicleType] ?? '';
            $vehiclePrinter->vehiclePrice = $datum['vehiclePrice'] ?? '';
            $vehiclePrinter->vehiclePriceWithOutTax = $datum['vehiclePriceTax'] ?? '';
            $vehiclePrinter->vehicleSeat = $datum['vehicleSeat'] ?? '';
            $vehiclePrinter->remark = $datum['remark'] ?? '';
            $vehiclePrinter->familyName = $datum['carFamilyName'] ?? '';
            $tonCount = $datum['vehicleTonnage'] ?? 0;
            $vehiclePrinter->vehicleTonnage = round($tonCount) * 1000;
            $vehiclePrinter->wholeWeight = round(round($datum['maxVehicleQuality'] ?? '0',3) * 1000);

            $vehiclePrinter->energyTypeCode = 'E01';//无
            $vehiclePrinter->energyTypeName = IDockEnums::$energyType[$vehiclePrinter->energyTypeCode] ?? '';


//            //新能源
//            if (in_array($vehiclePrinter->energyTypeCode,['E02','E03','E04'])) {
//                $vehiclePrinter->isNewEnergy = '1';
//            }
            $this->printer->setModelList($vehiclePrinter);
        }

        return $this;
    }
}
